package ph.com.gs3.formalistics.fragments.workers;

import android.app.Activity;
import android.app.Fragment;
import android.os.AsyncTask;

public class TesterWorkerFragment extends Fragment {

	public static final String TAG = TesterWorkerFragment.class.getSimpleName();

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	public void startTask() {

		TestBackgroundTask backgroundTask = new TestBackgroundTask();
		backgroundTask.execute((TesterWorkerCallbacks) getActivity());
	}

	// ========================================================================
	// Callback Interfaces

	public static interface TesterWorkerCallbacks {

		public void onProcessFinished();

	}

	// ========================================================================
	// Background Tasks

	private static class TestBackgroundTask extends AsyncTask<TesterWorkerCallbacks, Void, Void> {

		TesterWorkerCallbacks callback;

		@Override
		protected Void doInBackground(TesterWorkerCallbacks... params) {

			this.callback = params[0];

			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);

			this.callback.onProcessFinished();
		}

	}

}
